Ti.include('database.js');

function Favorite(){
	
	var self = Ti.UI.createWindow({
		layout:"vertical",
		backgroundColor:'#ffffff'
	});
	
	
	var mainView = Ti.UI.createScrollView({
		layout:'vertical'
	});
	
	var btnAdd = Ti.UI.createButton({
		title:'Add FAP'
	});
	
	btnAdd.addEventListener('click',function(e){
   		var newId = insertFavorite('Microsoft','Apple', 'Facebook');
  	});
	
	var btnRead = Ti.UI.createButton({
		title:'Read FAP'
	});
	
	var data = []; //empty data array
	var tblFavorites = Titanium.UI.createTableView({
	  height: 366,
	  width: 320,
	  top: 0,
	  left: 0
	});
	
	btnRead.addEventListener('click',function(e){
   		data = []; //set our data object to empty
 		data = getFavorites();
  		tblFavorites.data = data;
  	});
  	
	mainView.add(btnAdd);
	mainView.add(btnRead);
	mainView.add(tblFavorites);
	
	self.add(mainView);
	return self;
}
module.exports = Favorite;